'use strict';

var Money = require('../models/money'),
    formatDate = require('../helpers/format-date');

exports.portal = function* () {
    //var data = localData.getLatestInfo(50);
    var result = yield Money.getInfo;
    result.data = result.data.slice(0, 50);
    result.defaultDate = formatDate(this.query.lastModifyDate || new Date());
    result.inChina = !!this.query.cn;
    yield this.render('portal', result, {
        commands: {
            formatDate: function(scope, options) {
                return formatDate(options.params[0]);
            }
        }
    });
};

exports.insert = function* () {
    var newData = yield Money.insert(this.request.body);
    this.redirect('/?lastModifyDate=' + formatDate(newData.date));
};
